home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / dnet / dshterm1_0.lha / lib / st / examples / filetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  3.9 KB  |  127 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/ports.h>
  4. #include <dos/dos.h>
  5. #include <dos/dosextens.h>
  6. #include <proto/exec.h>
  7. #include <proto/dos.h>
  8. #include <st/st_proto.h>
  9. #include <intuition/intuition.h>
  10.  
  11. main(int argc, char *argv[])
  12. {
  13. struct    FileHandle *fh = NULL;
  14. long    out = NULL, file = NULL, err = NULL, n1, n2;
  15. char    *prg, buf[1000];
  16. struct MsgPort *ourport = NULL;
  17. struct StandardPacket *stdpkt = NULL, *stdpkt2;
  18. struct InfoData *info;
  19. struct Window *window;
  20.  
  21.     out = Output();
  22.     err = Open("*",MODE_OLDFILE);
  23.     prg = FindTask(NULL)->tc_Node.ln_Name;
  24.  
  25.     fpf(out, "%s [%s]: %08lx memory pointer\n",
  26.             prg, argv[0], FindTask(NULL)->tc_MemEntry);
  27.  
  28.     if(!(file = Open(argv[1], MODE_OLDFILE) )) {
  29.         fpf(err,"%s: Couldn't open that nasty file\n", prg);
  30.         goto cleanup;
  31.     }
  32.  
  33.     fh = (struct FileHandle *)(file<<2);
  34.     fpf(out,"File opened ok! Now for some statistic type stuff:\n"
  35.             "File Handle at %08lx (BCPL %08lx)\n\n"
  36.  
  37.             "fh_Link %08lx (EXEC message)\n"
  38.             "fh_Port %08lx (Reply port)\n"
  39.             "fh_Type %08lx (Dest port)\n"
  40.             "fh_Args %08lx (arg1)\n",
  41.             fh, file, fh->fh_Link, fh->fh_Port, fh->fh_Type, fh->fh_Args);
  42.  
  43. /** GET A PORT AND SOME MEMORY */
  44.     if(!(ourport = CreatePort("TestAsyncIO",0))) {
  45.         fpf(err,"Couldn't create a port!\n");
  46.         goto cleanup; }
  47.     if(!(stdpkt = (struct StandardPacket *)
  48.         AllocMem(sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR) )) {
  49.             fpf(err,"Couldn't allocate memory!\n");
  50.             goto cleanup; }
  51.     if(!(info = (struct InfoData *)
  52.         AllocMem(sizeof(struct InfoData), MEMF_CHIP | MEMF_CLEAR)) ) {
  53.             fpf(err,"Couldn't get memory!\n");
  54.             goto cleanup; }
  55.  
  56.     if(!(stdpkt2 = (struct StandardPacket *)
  57.         AllocMem(sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR) )) {
  58.             fpf(err,"Couldn't allocate memory!\n");
  59.             goto cleanup; }
  60.  
  61. /** CONSTRUCT A PACKET & SEND IT */
  62. /*    n = Read(file, buf, 1000); */
  63.     fpf( err,    "pkt=%08lx msg=%08lx por=%08lx act=%08lx\n"
  64.                 "ag1=%08lx ag2=%08lx ag3=%08lx\n",
  65.     stdpkt->sp_Msg.mn_Node.ln_Name = (char *)&(stdpkt->sp_Pkt),
  66.     stdpkt->sp_Pkt.dp_Link = &(stdpkt->sp_Msg),
  67.     stdpkt->sp_Pkt.dp_Port = ourport,
  68.     stdpkt->sp_Pkt.dp_Type = ACTION_DISK_INFO,
  69.     stdpkt->sp_Pkt.dp_Arg1 = ((long)info)>>2,
  70.     stdpkt->sp_Pkt.dp_Arg2 = 0,
  71.     stdpkt->sp_Pkt.dp_Arg3 = 0 );
  72.     PutMsg (fh->fh_Type, &(stdpkt->sp_Msg));
  73.     fpf(out,"Waiting...\n");
  74.     Wait(1<<ourport->mp_SigBit);
  75.     GetMsg(ourport);
  76.     n1 = stdpkt->sp_Pkt.dp_Res1;
  77.     fpf(err,"Result=%08lx\n", n1);
  78.     fpf(err,"nse=%08lx un=%08lx ds=%08lx nb=%08lx nbu=%08lx\n"
  79.             "bpb=%08lx dt=%08lx vn=%08lx iu=%08lx\n",
  80.             info->id_NumSoftErrors,
  81.             info->id_UnitNumber,
  82.             info->id_DiskState,    
  83.             info->id_NumBlocks,    
  84.             info->id_NumBlocksUsed,
  85.             info->id_BytesPerBlock,
  86.             info->id_DiskType,
  87.             info->id_VolumeNode,
  88.             info->id_InUse );
  89.     window = (struct Window *)info->id_VolumeNode;
  90.     fpf(err,"Window:\n"
  91.             "bl=%ld bt=%ld br=%ld bb=%ld\n"
  92.             "GZZWIdth=%ld, GZZHeight=%ld\n",
  93.             window->BorderLeft, window->BorderTop, window->BorderRight,
  94.             window->BorderBottom,
  95.             window->GZZWidth, window->GZZHeight );
  96.     if(window->IFont) {
  97.         fpf(err,"Font: x=%ld y=%ld, dims: X=%ld, Y=%ld\n",
  98.             window->IFont->tf_XSize,
  99.             window->IFont->tf_YSize,
  100.             window->GZZWidth / window->IFont->tf_XSize,
  101.             window->GZZHeight / window->IFont->tf_YSize );
  102.     }
  103.     stdpkt2->sp_Msg.mn_Node.ln_Name = (char *)&(stdpkt2->sp_Pkt);
  104.     stdpkt2->sp_Pkt.dp_Link = &(stdpkt2->sp_Msg);
  105.     stdpkt2->sp_Pkt.dp_Port = ourport;
  106.     stdpkt2->sp_Pkt.dp_Type = ACTION_READ;
  107.     stdpkt2->sp_Pkt.dp_Arg1 = fh->fh_Args;
  108.     stdpkt2->sp_Pkt.dp_Arg2 = (long)buf;
  109.     stdpkt2->sp_Pkt.dp_Arg3 = 990;
  110.     PutMsg (fh->fh_Type, &(stdpkt2->sp_Msg));
  111.     fpf(out,"Waiting...\n");
  112.     Wait(1<<ourport->mp_SigBit);
  113.     GetMsg(ourport);
  114.     n2 = stdpkt2->sp_Pkt.dp_Res1;
  115.  
  116.     Write(Output(), buf, n2);
  117.  
  118. cleanup:
  119.     if(stdpkt) FreeMem(stdpkt, sizeof(struct StandardPacket));
  120.     if(stdpkt2) FreeMem(stdpkt2, sizeof(struct StandardPacket));
  121.     if(info) FreeMem(info, sizeof(struct InfoData));
  122.     if(ourport) DeletePort(ourport);
  123.     SafeClose(&file);
  124.     SafeClose(&err);
  125. }
  126.  
  127.